import { ResultData, Role } from "@/api/interface/index";
import { PORT_Role } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 角色管理模块
 */
// 获取角色列表
export const getRoleList = (params: Role.ReqRoleParams) => {
  return http.post<Role.ResRoleList[]>(PORT_Role + `/list`, params);
};

// 保存角色
export const saveRole = (params: Role.ReqRoleSaveParams) => {
  return http.post<number>(PORT_Role + `/save`, params);
};

// 删除角色
export const deleteRole = (params: Role.ReqRoleDeleteParams) => {
  return http.post<boolean>(PORT_Role + `/delete`, params);
};

// 获取权限树
export const getPermissionTree = () => {
  return http.get<Role.PermissionNode[]>(PORT_Role + `/permission-tree`);
};

// 获取角色权限
export const getRolePermissions = (roleId: number) => {
  return http.get<number[]>(PORT_Role + `/role-permissions/${roleId}`);
};

// 设置角色权限
export const setRolePermissions = (params: Role.ReqSetRolePermissionsParams) => {
  return http.post<ResultData<boolean>>(PORT_Role + `/set-role-permissions`, params);
};
